from PIL import ImageChops
from PIL import Image
import pyautogui as pat
import time

from PIL import Image


def make_regalur_image(img, size=(128, 128)):
    return img.resize(size).convert('RGB')


def hist_similar(lh, rh):
    assert len(lh) == len(rh)
    return sum(1 - (0 if l == r else float(abs(l - r)) / max(l, r)) for l, r in zip(lh, rh)) / len(lh)


def calc_similar(li, ri):
    return hist_similar(li.histogram(), ri.histogram())


def first(img1,img2):
    img1 = make_regalur_image(img1)

    img2 = make_regalur_image(img2)
    result=calc_similar(img1, img2)
    #print(result)
    if result>0.85:
        return True
    return False

def second(img1,img2):
    img1 = make_regalur_image(img1)

    img2 = make_regalur_image(img2)
    result=calc_similar(img1, img2)
    #print(result)
    if result>=0.70:
        return True
    return False

